package databases

import (
	"Godzilla/common/ini"
	"log"
)

var mysqlMap = make(map[string]string)

func GetMysqlConfig(str string) string {

	return mysqlMap[str]
}

func SetMysqlConfig(key string, value string) bool {
	mysqlMap[key] = value
	if _, err :=mysqlMap[key]; err == false {
		return false
	}
	return true
}

func MysqlSetConfig() bool {
	var (
		Name 		string
		Host 		string
		Port 		string
		User 		string
		Password 	string

	)
	driver := "mysql"


	cfg, err := ini.NewIni()
	if err != nil {
		log.Println(err)
		return false
	}

	Name 		= cfg.Section(driver).Key("Name").String()
	Host 		= cfg.Section(driver).Key("Host").String()
	Port 		= cfg.Section(driver).Key("Port").String()
	User 		= cfg.Section(driver).Key("User").String()
	Password	= cfg.Section(driver).Key("Password").String()

	SetMysqlConfig("Name",Name)
	SetMysqlConfig("Host",Host)
	SetMysqlConfig("Port",Port)
	SetMysqlConfig("User",User)
	SetMysqlConfig("Password",Password)

	return true
}

